#region License, Terms and Conditions
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */
#endregion
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using raya.Models.login;
using raya.Models.people;

namespace raya.Controllers
{
    //[HandleError]
    public class searchController : baseController
    {
        public ActionResult Index()
        {
            if (Session["id"] == null)
            {
                return RedirectToLogin();
            }
            string error = "";
		    HashSet<login> results = null;
            HashSet<login> friends = null;
		    if (!String.IsNullOrEmpty(Request.QueryString["q"])) 
            {
			    var people =  new people();
                friends = people.GetFriends(Session["id"].ToString());
                results = people.Search(Request.QueryString["q"]);
		    } 
            else 
            {
			    error = "no search phrase given";
		    }
            PersonSearchResult value = new PersonSearchResult {error = error, results = results, friends = friends};
            return View("search", value);
        }
    }
}
